Allow a client to override values in a config
authorNick Cameron <ncameron@mozilla.com>
Mon, 3 Apr 2017 02:08:15 +0000 (14:08 +1200)
committerNick Cameron <ncameron@mozilla.com>
Mon, 3 Apr 2017 02:08:15 +0000 (14:08 +1200)
src/cargo/util/config.rs
src/cargo/util/mod.rs

index c0527a760691114021de6908043dc690c4ef2a1f..17e909b97a2fe8e4667b4c2b53fa1bf1e109b0fe 100644 (file)
@@ -109,6 +109,16 @@ impl Config {
         self.values.get_or_try_init(|| self.load_values())
     }
 
+    pub fn set_values(&self, values: HashMap<String, ConfigValue>) -> CargoResult<()> {
+        if self.values.borrow().is_some() {
+            return Err(human("Config values already found"));
+        }
+        match self.values.fill(values) {
+            Ok(()) => Ok(()),
+            Err(_) => Err(human("Could not fill values")),
+        }
+    }
+
     pub fn cwd(&self) -> &Path { &self.cwd }
 
     pub fn target_dir(&self) -> CargoResult<Option<Filesystem>> {
@@ -378,7 +388,7 @@ impl Config {
         !self.frozen.get() && !self.locked.get()
     }
 
-    fn load_values(&self) -> CargoResult<HashMap<String, ConfigValue>> {
+    pub fn load_values(&self) -> CargoResult<HashMap<String, ConfigValue>> {
         let mut cfg = CV::Table(HashMap::new(), PathBuf::from("."));
 
         walk_tree(&self.cwd, |mut file, path| {
index 27da14148c26c363b2f69362129aae5105abae4a..9010a11a4c232fb364b2093a4d383299579a214d 100644 (file)
@@ -1,5 +1,5 @@
 pub use self::cfg::{Cfg, CfgExpr};
-pub use self::config::{Config, homedir};
+pub use self::config::{Config, ConfigValue, homedir};
 pub use self::dependency_queue::{DependencyQueue, Fresh, Dirty, Freshness};
 pub use self::errors::{CargoResult, CargoError, Test, ChainError, CliResult};
 pub use self::errors::{CliError, ProcessError, CargoTestError};